package com.sqx.modules.creation.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.dao.UserDao;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.creation.dao.*;
import com.sqx.modules.creation.entity.*;
import com.sqx.modules.creation.entity.dto.AuditCreationDto;
import com.sqx.modules.creation.entity.dto.GetCreationListDto;
import com.sqx.modules.creation.entity.dto.SelCreationListDto;
import com.sqx.modules.creation.entity.dto.UserWriteDto;
import com.sqx.modules.creation.entity.vo.*;
import com.sqx.modules.creation.service.CreationService;
import org.apache.commons.lang3.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.object.SqlFunction;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 创作表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024年09月03日
 */
@Service
public class CreationServiceImpl extends ServiceImpl<CreationDao, NCreation> implements CreationService {

    @Autowired
    private CreationDao creationDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserBehaviorDao userBehaviorDao;
    @Autowired
    private FollowsUserDao followsUserDao;
    @Autowired
    private CreationCommentDao creationCommentDao;
    @Autowired
    private LabelDao labelDao;
    @Autowired
    private CreationGoodDao creationGoodDao;

    /**查询所有创作列表*/
    @Override
    public Result getCreationList(GetCreationListDto getCreationListDto) {
        Page<NCreation> page = new Page<>(ObjectUtils.isEmpty(getCreationListDto.getPage()) ? 1 : getCreationListDto.getPage(), ObjectUtils.isEmpty(getCreationListDto.getLimit()) ? 10 : getCreationListDto.getLimit());
        //string类型的时间转为date
        IPage<GetCreationListVo> getCreationListVos = creationDao.getCreationList(page,
                getCreationListDto.getUserName(),getCreationListDto.getCreationClassify(),
                getCreationListDto.getStartTime(),getCreationListDto.getEndTime(),
                getCreationListDto.getLabelId(),getCreationListDto.getCreationStatus());
        if (ObjectUtils.isNotEmpty(getCreationListVos.getRecords())){
            for (GetCreationListVo record : getCreationListVos.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")) {
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    // 将JSONArray转换为集合
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    record.setCreationPicture(result);
                }else {
                    record.setCreationPicture(null);
                }
            }
        }
        return Result.success().put("data",new PageUtils(getCreationListVos));
    }

    /**
     * 热门
     * @param userId
     * @param selCreationListDto
     * @return
     */
    @Override
    public Result selCreationList(Long userId, SelCreationListDto selCreationListDto) {
        if (ObjectUtils.isEmpty(selCreationListDto.getLabelId())||selCreationListDto.getLabelId()>3) {
            Page<NCreation> creationPage = new Page<>(ObjectUtils.isEmpty(selCreationListDto.getPage()) ? 1 : selCreationListDto.getPage(), ObjectUtils.isEmpty(selCreationListDto.getLimit()) ? 10 : selCreationListDto.getLimit());
            IPage<SelCreationListVo> listVoIPage = creationDao.selCreationListByLabel(creationPage,selCreationListDto.getCity(),userId,selCreationListDto.getLabelId());
            for (SelCreationListVo record : listVoIPage.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")) {
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    record.setCreationPicture(result);
                }
            }
            return Result.success().put("data",new PageUtils(listVoIPage));
        }else if (selCreationListDto.getLabelId()==1) {//热门(作品点赞高的)
            Page<NCreation> creationPage = new Page<>(ObjectUtils.isEmpty(selCreationListDto.getPage()) ? 1 : selCreationListDto.getPage(), ObjectUtils.isEmpty(selCreationListDto.getLimit()) ? 10 : selCreationListDto.getLimit());
            IPage<SelCreationListVo> listVoIPage = creationDao.selCreationListByHot(creationPage,userId);
            for (SelCreationListVo record : listVoIPage.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")) {
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    record.setCreationPicture(result);
                }
            }
            return Result.success().put("data",new PageUtils(listVoIPage));
        }else if (selCreationListDto.getLabelId() ==2) {//同城
            Page<NCreation> creationPage = new Page<>(ObjectUtils.isEmpty(selCreationListDto.getPage()) ? 1 : selCreationListDto.getPage(), ObjectUtils.isEmpty(selCreationListDto.getLimit()) ? 10 : selCreationListDto.getLimit());
            IPage<SelCreationListVo> listVoIPage = creationDao.selCreationList(creationPage,selCreationListDto.getCity(),userId);
            for (SelCreationListVo record : listVoIPage.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")) {
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    record.setCreationPicture(result);
                }
            }
            return Result.success().put("data",new PageUtils(listVoIPage));
        } else if (selCreationListDto.getLabelId()==3) {//视频
            Page<NCreation> creationPage = new Page<>(ObjectUtils.isEmpty(selCreationListDto.getPage()) ? 1 : selCreationListDto.getPage(), ObjectUtils.isEmpty(selCreationListDto.getLimit()) ? 10 : selCreationListDto.getLimit());
            IPage<SelCreationListVo> listVoIPage = creationDao.selCreationListByClassify(creationPage,userId);
            for (SelCreationListVo record : listVoIPage.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")) {
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    record.setCreationPicture(result);
                }
            }
            return Result.success().put("data",new PageUtils(listVoIPage));
        }
        return Result.success();
    }

    @Override
    public Result userWrite(Long userId,UserWriteDto userWriteDto) {
        //当图片为null时，这里复制会将NCreation的String类型的creationPicture赋值为[]
        NCreation creation = BeanUtil.toBean(userWriteDto, NCreation.class);
        if(userWriteDto.getCreationClassify()==1){
            if (ObjectUtils.isNotEmpty(userWriteDto.getCreationPicture())&&userWriteDto.getCreationPicture().size()>0){
                // 将数组转换为JSON数组
                JSONArray jsonArray = new JSONArray(userWriteDto.getCreationPicture());
                // 将JSON数组转换为字符串
                String creationPictureJson = jsonArray.toString();
                creation.setCreationPicture(creationPictureJson);
            }else {
                creation.setCreationPicture(null);
            }
        }
        creation.setUserId(userId.intValue());
        creation.setCreateTime(new Date());
        creation.setCreationStatus(0);
        creationDao.insert(creation);
        return Result.success();
    }

    @Override
    public Result getMyCreationList(Long userId, Integer page, Integer limit, Long selUserId,Long classify) {
        Page<NCreation> voPage = new Page<>(ObjectUtils.isEmpty(page) ? 1 : page, ObjectUtils.isEmpty(limit) ? 10 : limit);
        IPage<GetMyCreationListVo> getMyCreationListVoIPage = creationDao.getMyCreationList(voPage,userId,selUserId,classify);
        if (ObjectUtils.isNotEmpty(getMyCreationListVoIPage.getRecords())){
            for (GetMyCreationListVo record : getMyCreationListVoIPage.getRecords()) {
                if (ObjectUtils.isNotEmpty(record.getCreationPictures())&&!record.getCreationPictures().equals("[]")){
                    JSONArray jsonArray = new JSONArray(record.getCreationPictures());
                    String input = jsonArray.toString();
                    // 将JSONArray转换为集合
                    input = input.replace("[", "").replace("]", "");
                    input = input.replace("\"", "");
                    String[] result = input.split(",");
                    if (result.length!=0)record.setCreationPicture(result);
                }
                if (!Objects.equals(userId.intValue(),record.getUserId())){
                    //是否关注
                    LambdaQueryWrapper<NFollowsUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                    lambdaQueryWrapper.eq(NFollowsUser::getUserId,userId);
                    lambdaQueryWrapper.eq(NFollowsUser::getFollowsId,record.getUserId());
                    Integer follow = followsUserDao.selectCount(lambdaQueryWrapper);
                    record.setFollowsStatus(follow);
                }
            }
        }
        return Result.success().put("data",new PageUtils(getMyCreationListVoIPage));

//        UserEntity user = userDao.selectById(selUserId);
//        LambdaQueryWrapper<NCreation> creationLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        creationLambdaQueryWrapper.eq(NCreation::getUserId,selUserId);
//        creationLambdaQueryWrapper.ne(NCreation::getCreationStatus,3);
//        creationLambdaQueryWrapper.eq(ObjectUtils.isNotEmpty(classify),NCreation::getCreationClassify,classify);
//        creationLambdaQueryWrapper.orderByDesc(NCreation::getCreateTime);
//        Page<NCreation> creationPage = new Page<>(ObjectUtils.isEmpty(page)?1:page, ObjectUtils.isEmpty(limit)?10:limit);
//        IPage<NCreation> creationIPage = creationDao.selectPage(creationPage, creationLambdaQueryWrapper);
//        if (ObjectUtils.isNotEmpty(creationIPage.getRecords())){
//            List<GetMyCreationListVo> list = creationIPage.getRecords().stream().map(o -> {
//                GetMyCreationListVo selCreationListVo = BeanUtil.toBean(o, GetMyCreationListVo.class);
//
//                if (ObjectUtils.isNotEmpty(o.getCreationPicture())){
//                    JSONArray jsonArray = new JSONArray(o.getCreationPicture());
//                    String input = jsonArray.toString();
//                    // 将JSONArray转换为集合
//                    input = input.replace("[", "").replace("]", "");
//                    input = input.replace("\"", "");
//                    String[] result = input.split(",");
//                    if (result.length==1){
//                        selCreationListVo.setCreationPicture(null);
//                    }else {
//                        selCreationListVo.setCreationPicture(result);
//                    }
//                }
//                selCreationListVo.setUserName(user.getUserName());
//                selCreationListVo.setUserAvatar(user.getAvatar());
//                //点赞数
//                LambdaQueryWrapper<NCreationGood> creationGoodLambdaQueryWrapper = new LambdaQueryWrapper<>();
//                creationGoodLambdaQueryWrapper.eq(NCreationGood::getCreationId,o.getCreationId());
//                Integer goodNum = creationGoodDao.selectCount(creationGoodLambdaQueryWrapper);
//                //评论数
//                LambdaQueryWrapper<NCreationComment> creationCommentLambdaQueryWrapper = new LambdaQueryWrapper<>();
//                creationCommentLambdaQueryWrapper.eq(NCreationComment::getCreationId,o.getCreationId());
//                Integer commentNum = creationCommentDao.selectCount(creationCommentLambdaQueryWrapper);
//                selCreationListVo.setGoodNum(goodNum);
//                selCreationListVo.setCommentNum(commentNum);
//
//                if (!Objects.equals(userId.intValue(),o.getUserId())){
//                    //是否关注
//                    LambdaQueryWrapper<NFollowsUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//                    lambdaQueryWrapper.eq(NFollowsUser::getUserId,userId);
//                    lambdaQueryWrapper.eq(NFollowsUser::getFollowsId,o.getUserId());
//                    Integer follow = followsUserDao.selectCount(lambdaQueryWrapper);
//                    selCreationListVo.setFollowsStatus(follow);
//                }
//                //是否点赞
//                LambdaQueryWrapper<NCreationGood> creationGoodLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
//                creationGoodLambdaQueryWrapper1.eq(NCreationGood::getUserId,userId);
//                creationGoodLambdaQueryWrapper1.eq(NCreationGood::getCreationId,o.getCreationId());
//                creationGoodLambdaQueryWrapper1.eq(NCreationGood::getReplyId,null);
//                creationGoodLambdaQueryWrapper1.eq(NCreationGood::getCommentId,null);
//                Integer good = creationGoodDao.selectCount(creationGoodLambdaQueryWrapper1);
//                selCreationListVo.setGoodStatus(good);
//
//                return selCreationListVo;
//            }).collect(Collectors.toList());
//            return Result.success().put("data",new PageUtils(list, Math.toIntExact(creationIPage.getTotal()), Math.toIntExact(creationIPage.getSize()), Math.toIntExact(creationIPage.getCurrent())));
//        }
       }

    @Override
    public Result getMyFollowList(Long userId, Integer page, Integer limit) {
        LambdaQueryWrapper<NFollowsUser> followsUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        followsUserLambdaQueryWrapper.eq(NFollowsUser::getUserId,userId);
        followsUserLambdaQueryWrapper.orderByDesc(NFollowsUser::getCreateTime);
        Page<NFollowsUser> followsUserPage = new Page<>(ObjectUtils.isEmpty(page)?1:page, ObjectUtils.isEmpty(limit)?10:limit);
        IPage<NFollowsUser> followsUserIPage = followsUserDao.selectPage(followsUserPage, followsUserLambdaQueryWrapper);
        if (ObjectUtils.isNotEmpty(followsUserIPage.getRecords())){
            List<Long> userIds = followsUserIPage.getRecords().stream().map(NFollowsUser::getFollowsId).collect(Collectors.toList());
            List<UserEntity> users = userDao.selectBatchIds(userIds);
            List<MyFollowListVo> followListVos = BeanUtil.copyToList(users, MyFollowListVo.class);
            return Result.success().put("data",new PageUtils(followListVos, Math.toIntExact(followsUserIPage.getTotal()), Math.toIntExact(followsUserIPage.getSize()), Math.toIntExact(followsUserIPage.getCurrent())));
        }
        return Result.success().put("data",new PageUtils(new ArrayList<MyFollowListVo>(), 0, 0, 0));
    }

    @Override
    public Result getMyFansList(Long userId, Integer page, Integer limit) {
        LambdaQueryWrapper<NFollowsUser> followsUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        followsUserLambdaQueryWrapper.eq(NFollowsUser::getFollowsId,userId);
        followsUserLambdaQueryWrapper.orderByDesc(NFollowsUser::getCreateTime);
        Page<NFollowsUser> followsUserPage = new Page<>(ObjectUtils.isEmpty(page)?1:page, ObjectUtils.isEmpty(limit)?10:limit);
        IPage<NFollowsUser> followsUserIPage = followsUserDao.selectPage(followsUserPage, followsUserLambdaQueryWrapper);
        if (ObjectUtils.isNotEmpty(followsUserIPage.getRecords())){
            List<Long> userIds = followsUserIPage.getRecords().stream().map(NFollowsUser::getUserId).collect(Collectors.toList());
            List<UserEntity> users = userDao.selectBatchIds(userIds);
            List<MyFansListVo> fansListVos = BeanUtil.copyToList(users, MyFansListVo.class);
            List<MyFansListVo> listVos = fansListVos.stream().map(o -> {
                LambdaQueryWrapper<NFollowsUser> userBehaviorLambdaQueryWrapper = new LambdaQueryWrapper<>();
                userBehaviorLambdaQueryWrapper.eq(NFollowsUser::getUserId, userId);
                userBehaviorLambdaQueryWrapper.eq(NFollowsUser::getFollowsId, o.getUserId());
                NFollowsUser followsUser = followsUserDao.selectOne(userBehaviorLambdaQueryWrapper);
                o.setIsFollow(ObjectUtils.isNotEmpty(followsUser) ? 1 : 0);
                return o;
            }).collect(Collectors.toList());
            return Result.success().put("data",new PageUtils(listVos, Math.toIntExact(followsUserIPage.getTotal()), Math.toIntExact(followsUserIPage.getSize()), Math.toIntExact(followsUserIPage.getCurrent())));
        }
        return Result.success().put("data",new PageUtils(new ArrayList<MyFansListVo>(), 0, 0, 0));
    }

    @Override
    public Result selLabels() {
        LambdaQueryWrapper<NLabel> labelLambdaQueryWrapper = new LambdaQueryWrapper<>();
        labelLambdaQueryWrapper.ne(NLabel::getLabelStatus,0);
        List<NLabel> labels = labelDao.selectList(labelLambdaQueryWrapper);
        return Result.success().put("data",labels);
    }

    /**
     * 删除文章
     * @param creationId
     * @return
     */
    @Override
    public Result deleteCreation(Long userId,Long creationId) {
        LambdaUpdateWrapper<NCreation> creationLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        creationLambdaUpdateWrapper.eq(NCreation::getCreationId,creationId);
        creationLambdaUpdateWrapper.eq(NCreation::getUserId,userId);
        creationLambdaUpdateWrapper.set(NCreation::getCreationStatus,3);
        creationDao.update(null,creationLambdaUpdateWrapper);
        return Result.success();
    }

    @Override
    public Result selCreationById(Long userId,Long creationId) {
        NCreation creation = creationDao.selectById(creationId);
        UserEntity user = userDao.selectById(creation.getUserId());
        SelCreationByIdVo selCreationByIdVo = BeanUtil.toBean(creation, SelCreationByIdVo.class);
        selCreationByIdVo.setUserName(user.getUserName());
        selCreationByIdVo.setUserAvatar(user.getAvatar());
        //图片
        if (ObjectUtils.isNotEmpty(creation.getCreationPicture())&&!creation.getCreationPicture().equals("[]")){
            JSONArray jsonArray = new JSONArray(creation.getCreationPicture());
            String input = jsonArray.toString();
            // 将JSONArray转换为集合
            input = input.replace("[", "").replace("]", "");
            input = input.replace("\"", "");
            String[] result = input.split(",");
            selCreationByIdVo.setCreationPicture(result);
        }else {
            selCreationByIdVo.setCreationPicture(null);
        }
        //点赞数
        LambdaQueryWrapper<NCreationGood> creationGoodLambdaQueryWrapper = new LambdaQueryWrapper<>();
        creationGoodLambdaQueryWrapper.eq(NCreationGood::getCreationId,creationId).
        isNull(NCreationGood::getCommentId).isNull(NCreationGood::getReplyId);
        Integer integer = creationGoodDao.selectCount(creationGoodLambdaQueryWrapper);
        selCreationByIdVo.setGoodNum(integer);
        //是否点赞
        LambdaQueryWrapper<NCreationGood> goodLambdaQueryWrapper = new LambdaQueryWrapper<>();
        goodLambdaQueryWrapper.eq(NCreationGood::getUserId,userId);
        goodLambdaQueryWrapper.eq(NCreationGood::getCreationId,creation.getCreationId());
        goodLambdaQueryWrapper.eq(NCreationGood::getReplyId,null);
        goodLambdaQueryWrapper.eq(NCreationGood::getCommentId,null);
        NCreationGood creationGood = creationGoodDao.selectOne(goodLambdaQueryWrapper);
        if (ObjectUtils.isNotEmpty(creationGood)){
            selCreationByIdVo.setGoodStatus(1);
        }else {
            selCreationByIdVo.setGoodStatus(0);
        }
        //关注人数
        LambdaQueryWrapper<NFollowsUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(NFollowsUser::getFollowsId,creation.getUserId());
        Integer followsNum = followsUserDao.selectCount(lambdaQueryWrapper);
        selCreationByIdVo.setFollowsNum(followsNum);
        //是否关注
        LambdaQueryWrapper<NFollowsUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(NFollowsUser::getUserId,userId);
        userLambdaQueryWrapper.eq(NFollowsUser::getFollowsId,creation.getUserId());
        NFollowsUser followsUser = followsUserDao.selectOne(userLambdaQueryWrapper);
        if (ObjectUtils.isNotEmpty(followsUser)){
            selCreationByIdVo.setFollowsStatus(1);
        }else {
            selCreationByIdVo.setFollowsStatus(0);
        }
        //评论数
        LambdaQueryWrapper<NCreationComment> commentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        commentLambdaQueryWrapper.eq(NCreationComment::getCreationId,creationId);
        Integer integer1 = creationCommentDao.selectCount(commentLambdaQueryWrapper);
        selCreationByIdVo.setCommentNum(integer1);
        return Result.success().put("data",selCreationByIdVo);
    }

    @Override
    public Result selUserInfo(Long userId,Long selUserId) {
//
//        UserEntity user = userDao.selectById(selUserId);
//        //作品点赞
//        LambdaQueryWrapper<NCreationGood> goodLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        goodLambdaQueryWrapper.eq(NCreationGood::getUserId,selUserId).isNull(NCreationGood::getCommentId)
//                .isNull(NCreationGood::getReplyId);
//        Integer integer = creationGoodDao.selectCount(goodLambdaQueryWrapper);
//        //粉丝数
//        LambdaQueryWrapper<NFollowsUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        userLambdaQueryWrapper.eq(NFollowsUser::getFollowsId,selUserId);
//        Integer integer1 = followsUserDao.selectCount(userLambdaQueryWrapper);
//        //关注数
//        LambdaQueryWrapper<NFollowsUser> userLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
//        userLambdaQueryWrapper1.eq(NFollowsUser::getUserId,selUserId);
//        Integer integer2 = followsUserDao.selectCount(userLambdaQueryWrapper1);
//        SelUserInfoVo selUserInfoVo = BeanUtil.toBean(user, SelUserInfoVo.class);
//        selUserInfoVo.setUserAvatar(user.getAvatar());
//        selUserInfoVo.setFansNum(integer1);
//        selUserInfoVo.setFollowNum(integer2);
//        selUserInfoVo.setGoodNum(integer);
//        //查询所有文章条数
//        LambdaQueryWrapper<NCreation> creationLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        creationLambdaQueryWrapper.eq(NCreation::getUserId,selUserId);
//        creationLambdaQueryWrapper.ne(NCreation::getCreationStatus,3);
//        Integer integer3 = creationDao.selectCount(creationLambdaQueryWrapper);
//        selUserInfoVo.setCreationNum(integer3);
//        //图文条数
//        LambdaQueryWrapper<NCreation> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(NCreation::getUserId,selUserId);
//        queryWrapper.eq(NCreation::getCreationClassify,1);
//        creationLambdaQueryWrapper.ne(NCreation::getCreationStatus,3);
//        Integer integer4 = creationDao.selectCount(queryWrapper);
//        selUserInfoVo.setArticleNum(integer4);
//        selUserInfoVo.setVideoNum(integer3-integer4);
        SelUserInfoVo userInfoVo = userDao.selUserInfo(userId,selUserId);
        if (!Objects.equals(selUserId, userId)){//是否关注
            LambdaQueryWrapper<NFollowsUser> lambdaQueryWrapper = new LambdaQueryWrapper<NFollowsUser>().eq(NFollowsUser::getUserId, userId).eq(NFollowsUser::getFollowsId, selUserId);
            NFollowsUser followsUser = followsUserDao.selectOne(lambdaQueryWrapper);
            if (ObjectUtils.isNotEmpty(followsUser)){
                userInfoVo.setIsFollow(1);
            }else {
                userInfoVo.setIsFollow(0);
            }
        }
        return Result.success().put("data",userInfoVo);
    }

    @Override
    public Result auditCreation(AuditCreationDto auditCreationDto) {
        LambdaUpdateWrapper<NCreation> creationLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        creationLambdaUpdateWrapper.eq(NCreation::getCreationId,auditCreationDto.getCreationId())
                .ne(NCreation::getCreationStatus,3)
                .set(NCreation::getCreationStatus,auditCreationDto.getAuditStatus())
                .set(NCreation::getUpdateTime,new Date());
        creationDao.update(null,creationLambdaUpdateWrapper);
        return Result.success();
    }

    @Override
    public Result getCreationDetail(Integer creationId) {

        NCreation creation = creationDao.selectById(creationId);
        NLabel label = labelDao.selectById(creation.getLabelId());
        GetCreationDetailVo creationDetailVo = BeanUtil.toBean(creation, GetCreationDetailVo.class);
        creationDetailVo.setLabelName(label.getLabelName());
        if (ObjectUtils.isNotEmpty(creation.getCreationPicture())){
            if (creation.getCreationPicture().equals("[]")){
                creationDetailVo.setCreationPicture(null);
            }else {
                JSONArray jsonArray = new JSONArray(creation.getCreationPicture());
                String input = jsonArray.toString();
                // 将JSONArray转换为集合
                input = input.replace("[", "").replace("]", "");
                input = input.replace("\"", "");
                String[] result = input.split(",");
                creationDetailVo.setCreationPicture(result);
            }
        }
        return Result.success().put("data", creationDetailVo);
    }

    @Override
    public Result deleteCreationById(Long[] creationIds) {
        LambdaUpdateWrapper<NCreation> creationLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        creationLambdaUpdateWrapper.in(NCreation::getCreationId,Arrays.asList(creationIds));
        creationLambdaUpdateWrapper.set(NCreation::getCreationStatus,3);
        creationLambdaUpdateWrapper.set(NCreation::getDeleteTime,new Date());
        creationDao.update(null,creationLambdaUpdateWrapper);
        return Result.success();
    }
}
